package com.zhang.family_doctor.controller;

import com.zhang.family_doctor.dto.PackagesListDto;
import com.zhang.family_doctor.dto.PackagesDto;
import com.zhang.family_doctor.entity.Packages;
import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.service.PackagesService;
import com.zhang.family_doctor.vo.PackagesVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 服务包管理
 */
@RestController
@RequestMapping("/packages")
@Slf4j
@Api(tags = "服务包管理")
public class PackagesController {

    @Autowired
    private PackagesService packagesService;

    @ApiOperation("新增服务包")
    @PostMapping("/save")
    public R<String> save(@RequestBody PackagesDto packagesDto, HttpServletRequest request){
        log.info("新增服务包：{}",packagesDto);
        return packagesService.save(packagesDto,request);
    }

    @ApiOperation("审核服务包")
    @PostMapping("/process")
    public R<String> process(Integer id,HttpServletRequest request){
        log.info("审核服务包：{}",id);
        return packagesService.process(id,request);
    }

    @ApiOperation("服务包驳回")
    @PostMapping("/reject")
    public R<String> reject(Integer id,String rejectionContent,HttpServletRequest request){
        log.info("服务包驳回：",id);
        return packagesService.reject(id,rejectionContent,request);
    }

    @ApiOperation("服务包停用")
    @PostMapping("/disable")
    public R<String> disable(Integer id,HttpServletRequest request){
        log.info("服务包停用：{}",id);
        return packagesService.disable(id,request);
    }

    @ApiOperation("服务包启用")
    @PostMapping("/enable")
    public R<String> enable(Integer id,HttpServletRequest request){
        log.info("服务包启用：{}",id);
        return packagesService.enable(id,request);
    }

    @ApiOperation("编辑服务包")
    @PostMapping("/updatePackage")
    public R<String> updatePackage(@RequestBody PackagesDto packagesDto,HttpServletRequest request){
        log.info("编辑服务包：{}",packagesDto);
        return packagesService.updatePackage(packagesDto,request);
    }

    @ApiOperation("根据服务包类型查询")
    @GetMapping("/getAll")
    public R<PackagesListDto> getAll(PackagesListDto getPackagesDto){
        log.info("根据服务包类型查询：{}",getPackagesDto);
        return packagesService.getAll(getPackagesDto);
    }

    @ApiOperation("查看服务包详情")
    @GetMapping("/getPackageDetails")
    public R<PackagesVO> getPackageDetails(Integer id){
        log.info("查看服务包详情：{}",id);
        return packagesService.getPackageDetails(id);
    }
}
